<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-yellow sidebar-mini">
<!--合格模态框-->
<div class="modal fade" data-backdrop="static" data-keyboard="false" id="modal-qualified">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">合格</h4>
            </div>
            <div class="modal-body">
                <form id="qualifiedForm" class="form-horizontal" role="form">
                    <div class="form-group">
                        <label class="col-sm-2 control-label no-padding-right">让步接收</label>
                        <div class="col-sm-10" style="padding-top: 5px">
                            <input name="id" type="hidden" style="display: none"/>
                            <input class="chatbox-working" type="checkbox" name="yield" value="1"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="result" class="col-sm-2 control-label no-padding-right">质检结果</label>
                        <div class="col-sm-10">
                            <textarea name="result" id="result" maxlength="255" style="resize: none"
                                      class="form-control" cols="70" rows="8" placeholder="请输入质检结果"></textarea>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button shiro:hasPermission="tran:testings:commit" type="button" class="btn btn-info"
                        id="btn-qualified-confirm">确定
                </button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>
<!--驳回模态框-->
<div class="modal fade" data-backdrop="static" data-keyboard="false" id="modal-reject">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">合格</h4>
            </div>
            <div class="modal-body">
                <form id="rejectForm" class="form-horizontal" role="form">
                    <div class="form-group">
                        <label class="col-sm-2 control-label no-padding-right">作废</label>
                        <div class="col-sm-10" style="padding-top: 5px">
                            <input name="id" type="hidden" style="display: none"/>
                            <input class="chatbox-working" type="checkbox" name="status" value="1"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="reason" class="col-sm-2 control-label no-padding-right">驳回原因</label>
                        <div class="col-sm-10">
                            <textarea name="reason" id="reason" maxlength="255" style="resize: none"
                                      class="form-control" cols="70" rows="8" placeholder="请输入驳回原因"></textarea>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button shiro:hasPermission="tran:testings:commit" type="button" class="btn btn-info"
                        id="btn-reject-confirm">确定
                </button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>
<section class="content-header">
    <h1>工艺卡转序-质检检验</h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm" class="form-horizontal" onkeydown="if(event.keyCode==13)return false;">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group margin-bottom-none"
                                     style="margin-left:0px;margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">
                                        用户名
                                    </label>
                                    <label class="control-label" th:text="${user.name}">
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">
                                        部门
                                    </label>
                                    <label class="control-label" th:text="${user.deptName}==null?'':${user.deptName}">
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">
                                        车间
                                    </label>
                                    <label class="control-label"
                                           th:text="${user.branchName}==null?'':${user.branchName}">
                                    </label>
                                </div>
                            </div>
                        </div>
                        <div class="row" shiro:hasPermission="tran:receive:edit">
                            <div class="form-inline">
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">
                                        生产令编号
                                    </label>
                                    <label class="control-label">
                                        <select id="select-prodNo" class="form-control" style="width: 140px;text-align: center">

                                        </select>
                                    </label>
                                    <label class="control-label">
                                        类型
                                    </label>
                                    <label class="control-label">
                                        <select id="select-special" class="form-control select2" style="width: 140px;text-align: center">

                                        </select>
                                    </label>
                                    <label class="control-label">
                                        部分
                                    </label>
                                    <label class="control-label">
                                        <select id="select-part" class="form-control select2" style="width: 200px;text-align: center">

                                        </select>
                                    </label>
                                    <label class="control-label">
                                        图号
                                    </label>
                                    <label class="control-label">
                                        <select id="select-drawNo" class="form-control select2" style="width: 300px;text-align: center">

                                        </select>
                                    </label>
                                </div>
                            </div>
                        </div>
                        <div class="row" shiro:hasPermission="tran:test:edit">
                            <div class="form-inline">
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">
                                        二维码区域
                                    </label>
                                    <label class="control-label">
                                        <input title="按回车键，即可获取转序内容。" id="QRCode" class="form-control" name="QRCode"
                                               onkeyup="loadData()" onfocus="showTips()" onblur="hideTips()"
                                               style="width: 500px;" value=""/>
                                    </label>
                                    <button type="button" class="btn btn-success" id="btn-search"
                                            onclick="loadData2()">
                                        <span class="Bold">搜索</span>
                                    </button>
                                    <label id="tips" class="control-label" style="color:red;display: none;">
                                        按回车键，即可获取转序内容。
                                    </label>
                                </div>
                            </div>
                        </div>
                        <div id="prodOrdAndProjectInfo" class="row" style="display: none">
                            <div class="form-inline">
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">
                                        项目编号
                                    </label>
                                    <label id="proCode" class="control-label">
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">
                                        项目名称
                                    </label>
                                    <label id="proName" class="control-label">
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">
                                        项目数量
                                    </label>
                                    <label id="proQty" class="control-label">
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none"
                                     style="margin-left:0px;margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">
                                        生产令编号
                                    </label>
                                    <label id="prodNo" class="control-label">
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">
                                        生产令数量
                                    </label>
                                    <label id="prodNum" class="control-label">
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">
                                        需方
                                    </label>
                                    <label id="customer" class="control-label">
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">
                                        类型
                                    </label>
                                    <label id="prodTyp" class="control-label">
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">
                                        是否重点
                                    </label>
                                    <label id="prodIsKey" class="control-label">
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">
                                        交货日期
                                    </label>
                                    <label id="prodDelDat" class="control-label">
                                    </label>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="box-body">
                    <table id="bootstrap-table"></table>
                    <div id="noData1" class="col-md-12"
                         style="text-align: center;vertical-align: middle;display: none;"><h2>查无记录</h2></div>
                    <div id="noData2" class="col-md-12"
                         style="text-align: center;vertical-align: middle;display: none;"><h2>该零件已全部转序</h2></div>
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    let table;
    let status = ['', '未开始', '执行中', '部分转序', '全部转序'];
    let statusClass = ['', 'label-default', 'label-warning', 'label-success', 'label-success'];
    $(function () {
        /**
         * 模态框隐藏事件， 重置表单，重置验证
         */
        js.modal.hideEvent("modal-qualified", function () {
            $("#qualifiedForm")[0].reset();
        });
        /**
         * 模态框隐藏事件， 重置表单，重置验证
         */
        js.modal.hideEvent("modal-reject", function () {
            $("#rejectForm")[0].reset();
        });
        //加载数据
        loadTableData();
        //合格
        $("#btn-qualified-confirm").click(function () {
            let result = $("#qualifiedForm [name='result']").val();
            let yield = $("#qualifiedForm [name='yield']");
            if (yield.prop("checked") && (result === undefined || result === null || result.replace(/[\r\n]/g, "") === '')) {
                js.modal.warning('请输入质检结果！');
                return;
            }
            js.post({
                url: ctx + "transposition/check/qualified",
                data: $("#qualifiedForm").serialize(),
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                    } else {
                        js.modal.warning(result.msg);
                    }
                    js.table.refresh(table);
                    $("#qualifiedForm")[0].reset();
                    js.modal.hide('modal-qualified');
                }
            });
        });
        //驳回
        $("#btn-reject-confirm").click(function () {
            let reason = $("#rejectForm [name='reason']").val();
            if (reason === undefined || reason === null || reason.replace(/[\r\n]/g, "") === '') {
                js.modal.warning('请输入驳回原因！');
                return;
            }
            js.post({
                url: ctx + "transposition/check/reject",
                data: $("#rejectForm").serialize(),
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                    } else {
                        js.modal.warning(result.msg);
                    }
                    js.table.refresh(table);
                    $("#rejectForm")[0].reset();
                    js.modal.hide('modal-reject');
                }
            });
        });

        /** 生产令号下拉选 */
        js.post({
            url: ctx + "transposition/transpositionRec/getRecProdNoList",
            data: {},
            success: function (result) {
                $("#select-prodNo").html('').select2();
                let select2Html = '<option value=""></option>';
                for (let i = 0; i < result.data.length; i++) {
                    select2Html += '<option value="' + result.data[i].id + '">' + result.data[i].text + '</option>';
                }
                $("#select-prodNo").html(select2Html).select2();
                // $("#select-prodNo").val(result.data[0].id).select2();
                // $("#select-prodNo").val('');
                // getSpecials();
            }
        });

        /** 项目编号下拉框选中 */
        $("#select-prodNo").on("select2:select", function () {
            getSpecials();
        });

        /** 类型下拉框选中 */
        $("#select-special").on("select2:select", function () {
            getParts();
        });
        /** 部分下拉框选中 */
        $("#select-part").on("select2:select", function () {
            getDrawNos();
        });
        /** 图号下拉框选中 */
        $("#select-drawNo").on("select2:select", function () {
            if ($("#select-prodNo").val() != null && $("#select-prodNo").val() != '' && $("#select-drawNo").val() != null && $("#select-drawNo").val() != '' && $("#select-part").val() != null && $("#select-part").val() != '') {
                $("#QRCode").val($("#select-prodNo").val() + '|' + $("#select-drawNo").val() + '|' + $("#select-part").val() + '|1');
            } else {
                $("#QRCode").val('');
            }
            loadData2();
        });
    });

    /**
     * 显示提示
     */
    function showTips() {
        $("#tips").show();
    }

    /**
     * 隐藏提示
     */
    function hideTips() {
        $("#tips").hide();
    }

    /**
     * 获取类型列表
     */
    function getSpecials() {
        js.post({
            url: ctx + "transposition/transpositionRec/getRecProdNoSpecialList",
            data: {prodNo: $("#select-prodNo").val()},
            success: function (result) {
                $("#select-special").empty();
                let select2Html = '';
                for (let i = 0; i < result.data.length; i++) {
                    select2Html += '<option value="' + result.data[i].id + '">' + result.data[i].text + '</option>';
                }
                if (result.data.length > 0) {
                    $("#select-special").html(select2Html).select2();
                    $("#select-special").val(result.data[0].id).select2();
                }
                getParts();
            }
        });
    }

    /**
     * 获取部分列表
     */
    function getParts() {
        js.post({
            url: ctx + "transposition/transpositionRec/getRecProdNoPartList",
            data: {
                prodNo: $("#select-prodNo").val(),
                special: $("#select-special").val()
            },
            success: function (result) {
                $("#select-part").html('').empty();
                let select2Html = '';
                for (let i = 0; i < result.data.length; i++) {
                    select2Html += '<option value="' + result.data[i].id + '">' + result.data[i].text + '</option>';
                }
                if (result.data.length > 0) {
                    $("#select-part").html(select2Html).select2();
                    $("#select-part").val(result.data[0].id).select2();
                }
                getDrawNos();
            }
        });
    }

    /**
     * 获取图号列表
     */
    function getDrawNos() {
        js.post({
            url: ctx + "transposition/transpositionRec/getRecProdNoDrawNoList",
            data: {
                prodNo: $("#select-prodNo").val(),
                special: $("#select-special").val(),
                partId: $("#select-part").val()
            },
            success: function (result) {
                $("#select-drawNo").html('').empty();
                let select2Html = '';
                for (let i = 0; i < result.data.length; i++) {
                    select2Html += '<option value="' + result.data[i].id + '">' + result.data[i].text + '</option>';
                }
                if (result.data.length > 0) {
                    $("#select-drawNo").html(select2Html).select2();
                    $("#select-drawNo").val(result.data[0].id).select2();
                }
                if ($("#select-prodNo").val() != null && $("#select-prodNo").val() != '' && $("#select-drawNo").val() != null && $("#select-drawNo").val() != '' && $("#select-part").val() != null && $("#select-part").val() != '') {
                    $("#QRCode").val($("#select-prodNo").val() + '|' + $("#select-drawNo").val() + '|' + $("#select-part").val() + '|1');
                } else {
                    $("#QRCode").val('');
                }
                loadData2();
            }
        });
    }
    /**
     * 检测回车
     */
    function loadData() {
        let ev = window.event || e;
        let keyCode = ev.keyCode ? ev.keyCode : ev.which ? ev.which : ev.charCode;
        if (keyCode == 13) {
            let qrCodeContent = $("#QRCode").val();
            if (qrCodeContent === '') {
                js.modal.warning("请扫描二维码！");
            } else {
                js.table.refresh(table);
                $.post(
                    ctx + 'transposition/transpositionRec/getProjectAndProdOrdInfo',
                    {
                        qrCode: $("#QRCode").val()
                    },
                    function (res) {
                        if(res.data!=null && res.data != undefined){
                            $("#proCode").text(res.data.proCode);
                            $("#proName").text(res.data.proName);
                            $("#proQty").text(res.data.proQty);
                            $("#prodNo").text(res.data.prodNo);
                            $("#prodNum").text(res.data.prodNum);
                            $("#customer").text(res.data.customer);
                            $("#prodTyp").text(res.data.prodTyp);
                            $("#prodIsKey").text(res.data.prodIsKey);
                            $("#prodDelDat").text(res.data.prodDelDat);
                            $("#prodOrdAndProjectInfo").show();
                        }else {
                            $("#prodOrdAndProjectInfo").hide();
                        }
                    }
                );
            }
        }
    }

    /**
     * 检测回车
     */
    function loadData2() {
        let qrCodeContent = $("#QRCode").val();
        if (qrCodeContent === '') {
            js.modal.warning("请扫描二维码！");
        } else {
            js.table.refresh(table);
            $.post(
                ctx + 'transposition/transpositionRec/getProjectAndProdOrdInfo',
                {
                    qrCode: $("#QRCode").val()
                },
                function (res) {
                    if(res.data!=null && res.data != undefined){
                        $("#proCode").text(res.data.proCode);
                        $("#proName").text(res.data.proName);
                        $("#proQty").text(res.data.proQty);
                        $("#prodNo").text(res.data.prodNo);
                        $("#prodNum").text(res.data.prodNum);
                        $("#customer").text(res.data.customer);
                        $("#prodTyp").text(res.data.prodTyp);
                        $("#prodIsKey").text(res.data.prodIsKey);
                        $("#prodDelDat").text(res.data.prodDelDat);
                        $("#prodOrdAndProjectInfo").show();
                    }else {
                        $("#prodOrdAndProjectInfo").hide();
                    }
                }
            );
        }
    }

    // /**
    //  * 申请质检
    //  */
    // function operRec(sheetId, id) {
    //     js.post({
    //         url: ctx + "transposition/check/rec",
    //         data: {
    //             id: id,
    //             sheetId: sheetId
    //         },
    //         success: function (result) {
    //             if (result.type === web_status.SUCCESS) {
    //                 js.modal.success(result.msg);
    //             } else {
    //                 js.modal.warning(result.msg);
    //             }
    //             js.table.refresh(table);
    //         }
    //     });
    // }

    function loadTableData() {
        $('#bootstrap-table').bootstrapTable('destroy');//这里必须要添加这个销毁，否则新增、修改、查看的切换可编辑列表中的数据可能加载出现问题。
        /**
         * 加载列表
         */
        table = js.table.init({
            url: ctx + "transposition/check/list",
            showColumns: false,
            showExport: false,
            editable: true,//开启编辑模式
            uniqueId: 'id',
            onLoadSuccess: function (data) {
                if( $("#QRCode").val().trim().length>0 && data.rows.length===0){
                    $.post(
                        ctx + 'transposition/check/completeCount',
                        {
                            QRCode: $("#QRCode").val()
                        },
                        function (res) {
                            if(res.data===0){
                                $("#noData1").show();
                                $("#noData2").hide();
                                $("#bootstrap-table").hide();
                            }else{
                                $("#noData1").hide();
                                $("#noData2").show();
                                $("#bootstrap-table").hide();
                            }
                        }
                    );
                }else{
                    $("#noData1").hide();
                    $("#noData2").hide();
                    $("#bootstrap-table").show();
                }
            },
            columns: [
                {
                    title: '序号', width: '60',
                    formatter: function (value, row, index, field) {
                        var pageSize = table.bootstrapTable('getOptions').pageSize;
                        var pageNumber = table.bootstrapTable('getOptions').pageNumber;
                        return pageSize * (pageNumber - 1) + index + 1;
                    }
                },
                {
                    title: '生产令号', field: 'prodNo', width: '110',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }

                    }
                },
                {
                    title: '项目名称', field: 'proName',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }

                    }
                },
                {
                    title: '类型', field: 'special', width: '90',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }

                    }
                },
                {
                    title: '部分', field: 'part', width: '150',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }
                    }
                },
                {
                    title: '图号', field: 'drawNo', width: '90',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }
                    }
                },
                {
                    title: '零件名称', field: 'drawName', width: '90',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }
                    }
                },
                {
                    title: '零件数量',
                    field: 'drawNum',
                    width: '90',
                    edit: {type: 'text'},
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }
                    }
                },
                {
                    title: '工艺路线', field: 'route', width: '90',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }
                    }
                },

                {
                    title: '质检数量', field: 'num', width: '150',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }
                    }
                },
                {
                    title: '路线状态', field: 'status', width: '90',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            //  /** 状态 1=未开始 2=执行中 3=部分转序 4=全部转序 */
                            return '<label class="badge ' + statusClass[value] + '">' + status[value] + '</label>';
                        } else {
                            return '--';
                        }
                    }
                },
                {
                    title: '申请质检时间', field: 'applyTime', width: '90',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }
                    }
                },
                {
                    title: '操作', width: '140',
                    formatter: function (value, row, index) {
                        let elements = new Array();
                        if (hasP('tran:testings:commit')) {
                            if (row.status === 2 || row.status === 3) {
                                elements.push('<button class="btn btn-success btn-xs" onclick="qualified(' + row.id + ')">质检合格</button>');
                                elements.push('<button class="btn btn-danger btn-xs" onclick="reject(' + row.id + ')">质检驳回</button>');
                            }
                        }
                        return elements.join('');
                    }
                }
            ]
        });
    }


    /**
     * 打开合格模态框
     */
    function qualified(id) {
        $("#qualifiedForm [name='id']").val(id);
        js.modal.open('modal-qualified');
    }

    /**
     * 打开驳回模态框
     */
    function reject(id) {
        $("#rejectForm [name='id']").val(id);
        js.modal.open('modal-reject');
    }


</script>
</body>
</html>